package com.example.demo.mapper;

import com.example.demo.mapper.entity.Coupons;
import com.example.demo.mapper.entity.StudentCoupons;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-19 22:06
 */
@Mapper
@Repository
public interface StudentCouponsMapper {
    @Select("SELECT * FROM coupons WHERE coupons_id = #{cousponsId}")
    Coupons selectCouponsById(int cousponsId);
    @Insert("INSERT INTO student_coupons (student_id, coupons_id, coupons_number) " +
            "VALUES (#{studentId}, #{couponsId}, #{couponsNumber})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertStudentCoupons(StudentCoupons studentCoupons);
    @Select("SELECT * FROM student_coupons WHERE student_id = #{studentId} AND status = #{status}")
    List<StudentCoupons> selectStatusCouponsList(@Param("studentId")int studentId, @Param("status")int status);
    @Select("SELECT * FROM student_coupons WHERE student_id = #{studentId} AND coupons_id = #{couponsId}")
    StudentCoupons selectStudentCoupons(@Param("studentId")int studentId, @Param("couponsId")int couponsId);
    @Select("SELECT store_address FROM advertiser WHERE advertiser_id = #{advertiserId}")
    String selectAddressById(int advertiserId);
    @Select("SELECT * FROM coupons WHERE end_date <= NOW() AND state != 3")
    List<Coupons> selectExpiredCoupons();
    @Update("UPDATE student_coupons SET status = 3 WHERE coupons_id = #{couponsId}")
    void updateExpiredStudentCoupons(int couponsId);
    @Update("UPDATE coupons SET state = 3 WHERE coupons_id = #{couponsId}")
    void updateExpiredCoupons(int couponsId);
    @Update("UPDATE student_coupons SET status = 2,updated_at=#{updatedAt} WHERE student_id = #{studentId} AND coupons_id = #{couponsId}")
    void updateStudentCouponsStatus(@Param("studentId")int studentId, @Param("couponsId")int couponsId,@Param("updatedAt")String updatedAt);
    @Select("SELECT * FROM student_coupons WHERE coupons_number = #{couponsNumber} AND status = 1")
    StudentCoupons selectStudentCouponsByNumber(String couponsNumber);
}
